package com.medical.project.system.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medical.framework.aspectj.lang.annotation.Log;
import com.medical.framework.aspectj.lang.enums.BusinessType;
import com.medical.project.system.domain.Area;
import com.medical.project.system.service.IAreaService;
import com.medical.framework.web.controller.BaseController;
import com.medical.framework.web.domain.AjaxResult;
import com.medical.common.utils.poi.ExcelUtil;
import com.medical.framework.web.page.TableDataInfo;

/**
 * 行政区域管理Controller
 *
 * @author ruoyi
 * @date 2020-05-24
 */
@RestController
@RequestMapping("/system/area")
public class AreaController extends BaseController {
    @Autowired
    private IAreaService areaService;

    /**
     * 查询行政区域管理列表（分页）
     */
    @PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(Area area) {
        startPage();
        List<Area> list = areaService.selectAreaList(area);
        return getDataTable(list);
    }

    /**
     * 查询全部行政区域
     *
     * @param area
     * @return
     */
    @GetMapping("/all")
    public TableDataInfo all(Area area) {
        List<Area> list = areaService.selectAreaList(area);
        return getDataTable(list);
    }

    /**
     * 导出行政区域管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:export')")
    @Log(title = "行政区域管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Area area) {
        List<Area> list = areaService.selectAreaList(area);
        ExcelUtil<Area> util = new ExcelUtil<Area>(Area.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 获取行政区域管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{areaCode}")
    public AjaxResult getInfo(@PathVariable("areaCode") String areaCode) {
        return AjaxResult.success(areaService.selectAreaById(areaCode));
    }

    /**
     * 新增行政区域管理
     */
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "行政区域管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Area area) {

        return toAjax(areaService.insertArea(area));
    }

    /**
     * 修改行政区域管理
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "行政区域管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Area area) {
        return toAjax(areaService.updateArea(area));
    }

    /**
     * 删除行政区域管理
     */
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "行政区域管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{areaCodes}")
    public AjaxResult remove(@PathVariable String[] areaCodes) {
        return toAjax(areaService.deleteAreaByIds(areaCodes));
    }
}
